package com.cs.study.homework._0315;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;

public class Demo {
    public static void main(String[] args) {

        // 去除重复元素
        ArrayList<User> list = new ArrayList<>();
        list.add(new User("ls", 18));
        list.add(new User("ls", 18));
        list.add(new User("wu", 18));
        list.add(new User("zl", 18));
        list.add(new User("zs", 18));

        //创建新的数组
        ArrayList<User> newList = new ArrayList<>();
        //遍历就数组
        for (User user : list) {
            //若新数组不包含该元素则添加
            if (!newList.contains(user)) {
                newList.add(user);
            }
        }

        System.out.println("list = " + list);
        System.out.println("newList = " + newList);

    }
}

@Data
@AllArgsConstructor
@NoArgsConstructor
class User {
    private String name;
    private int age;
}

